a =input("Введите четырех значное число:")
if len(a)!= 4 or not a.isdigit():
    print(0)
else:
    b = 0
    for i in range (4):
        for j in range (i + 1, 5):
            g = int(a[i:j])
            c = True
            if g <= 1:
                c = False
            else:
                for k in range (2, int(g**0.5) + 1):
                    if g % k == 0:
                        c = False
                        break
            if c and g > b:
                b = g
    print(b)
